/*
 * Copyright 2018 Shanxi Lu'an Taihang Laihui Net Tech co.,LTD.
 */
package com.wei;

import sun.applet.Main;

/**
 * Description:线程安全问题
 *
 * @author wzz
 * @since: 1.0
 * Create Date Time: 2018/11/3 17:24
 * Update Date Time:
 */
public  class MyThread extends Thread{

    private int count = 5;
    public  void run(){
        synchronized (this){
            count--;
            System.out.println("当前线程:"+Thread.currentThread().getName()+"输出结果为"+count);
        }
    }

    public static void main(String[] args) {
        MyThread myThread = new MyThread();
        Thread t1 = new Thread(myThread,"t1");
        Thread t2 = new Thread(myThread,"t2");
        Thread t3 = new Thread(myThread,"t3");
        Thread t4 = new Thread(myThread,"t4");
        Thread t5 = new Thread(myThread,"t5");

        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();
    }
}
